package aod.android.com.bernay.fixing.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.othershe.calendarview.bean.DateBean;
import com.othershe.calendarview.listener.OnPagerChangeListener;
import com.othershe.calendarview.listener.OnSingleChooseListener;
import com.othershe.calendarview.utils.CalendarUtil;
import com.othershe.calendarview.weiget.CalendarView;
import com.othershe.calendarview.weiget.WeekView;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseActivity;
import chen.lion.hilib.view.bind.HiView;

public class VideoTakenActivity extends BernayBaseActivity implements View.OnClickListener {

    @HiView(R.id.calendar)
    CalendarView calendarView;
    @HiView(R.id.fixing_weekview)
    WeekView fixing_weekview;
    @HiView(R.id.taken_date_tv)
    TextView taken_date_tv;
    @HiView(R.id.fixing_lastmonth_iv)
    ImageView fixing_lastmonth_iv;
    @HiView(R.id.fixing_nextmonth_iv)
    ImageView fixing_nextmonth_iv;

    //共用日历布局  ---出差模式布局
    @HiView(R.id.on_business_lay)
    LinearLayout on_business_lay;
    //共用日历布局  ---行驶轨迹布局
    @HiView(R.id.travel_date_lay)
    LinearLayout travel_date_lay;
    //共用日历布局  ---视频调取布局
    @HiView(R.id.video_date_lay)
    LinearLayout video_date_lay;
    private String moudel = "0";//1为出差模式 2为行驶轨迹 3为视频调取

    private int[] cDate = CalendarUtil.getCurrentDate();
    private String starDate ="2000.1";
    private String endDate = "2050.12";

    @Override
    protected int initLayout() {
        return R.layout.activity_videotaken;
    }

    @Override
    protected void initData() {
        fixing_weekview.setBackgroundColor(getResources().getColor(R.color.taken_bg));
        fixing_lastmonth_iv.setOnClickListener(this);
        fixing_nextmonth_iv.setOnClickListener(this);
        if(getIntent().getStringExtra("moudel")!=null){
            moudel =  getIntent().getStringExtra("moudel");
        }
        final Bundle bundle =  new Bundle();
        if(moudel.equals("1")){
            on_business_lay.setVisibility(View.VISIBLE);
            travel_date_lay.setVisibility(View.GONE);
            video_date_lay.setVisibility(View.GONE);
            initTitle(getString(R.string.fixing_business_pattern), R.mipmap.icon_app_help, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bundle.putString("moudel","1");
                    goActivity(ExplainActivity.class,bundle);
                }
            });
        }
        if(moudel.equals("2")){
            on_business_lay.setVisibility(View.GONE);
            travel_date_lay.setVisibility(View.VISIBLE);
            video_date_lay.setVisibility(View.GONE);
            initTitle(getString(R.string.fixing_travel_pattern), R.mipmap.icon_app_help, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bundle.putString("moudel","2");
                    goActivity(ExplainActivity.class,bundle);
                }
            });
        }
        if(moudel.equals("3")){
            on_business_lay.setVisibility(View.GONE);
            travel_date_lay.setVisibility(View.GONE);
            video_date_lay.setVisibility(View.VISIBLE);
            initTitle(getString(R.string.video_taken_name), R.mipmap.icon_app_help, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bundle.putString("moudel","3");
                    goActivity(ExplainActivity.class,bundle);
                }
            });
        }


        //日历init，年月日之间用点号隔开
        calendarView
                .setStartEndDate(starDate, endDate)
                .setInitDate(cDate[0] + "." + cDate[1])
                .setSingleDate(cDate[0] + "." + cDate[1] + "." + cDate[2])
                .init();
        taken_date_tv.setText(cDate[0] + "年" + cDate[1] + "月");
        calendarView.setOnPagerChangeListener(new OnPagerChangeListener() {
            @Override
            public void onPagerChanged(int[] date) {
                taken_date_tv.setText(date[0] + "年" + date[1] + "月");
            }
        });
        calendarView.setOnSingleChooseListener(new OnSingleChooseListener() {
            @Override
            public void onSingleChoose(View view, DateBean date) {
                taken_date_tv.setText(date.getSolar()[0] + "年" + date.getSolar()[1] + "月");
            }
        });

        findViewById(R.id.gobtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goActivity(FixingMapActivity.class);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //上个月
            case R.id.fixing_lastmonth_iv :
                calendarView.lastMonth();
                break;
            //下个月
            case R.id.fixing_nextmonth_iv :
                calendarView.nextMonth();
                break;
        }
    }
}
